package com.yangyang.androidconnect.common;

import lombok.Data;

//统一响应体
@Data
public class ApiResult<T> {
    static final String MIME_JSON = "application/json;charset=utf-8";

    private int code;

    private String message;

    private T data;

    public ApiResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ApiResult<T> ok(String message, T data) {
        ApiResult<T> result = new ApiResult<>(200, message, data);
        return result;
    }

    public static <T> ApiResult<T> ok(T data) {
        ApiResult<T> result = new ApiResult<>(200, "请求成功", data);
        return result;
    }

    public static <T> ApiResult<T> error(String message) {
        ApiResult<T> result = new ApiResult<>(500, message, null);
        return result;
    }

    public static <T> ApiResult<T> error(int code, String message) {
        ApiResult<T> result = new ApiResult<>(code, message, null);
        return result;
    }
}
